const jwt = require('jsonwebtoken');

let createToken = function (data) {
    let token =  jwt.sign(data, process.env.SecretOrPublicKey, {
        expiresIn:  60 * 60 * 24 * 2 // 以s作为单位（目前设置的过期时间为3天）
    });
    return "Bearer " + token;
};

let verifyToken = function (token) {
    return new Promise((resolve, reject)=>{
        let info = jwt.verify(token.split(" ")[1], process.env.SecretOrPublicKey);
        resolve(info) ;
    })
};
module.exports = { createToken, verifyToken };